home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Macromedia Flash 4 / Sample Pages / Form / order.asp < prev    next >
Encoding:
Text File  |  1999-05-22  |  1.7 KB  |  59 lines

  1. <% 
  2.  
  3. ' Never cache this response
  4. Response.Expires = 0
  5.  
  6. ' Get data from their request
  7. total = Request.form("total")
  8. ccnum = Request.form("ccnum")
  9. ccdate = Request.form("ccdate")
  10. email = Request.form("email")
  11.  
  12. If total = 0 Then
  13.     ' They did not order anything
  14.     message = "Please check your order. You did select any items."
  15.     response.write("message="+URLEncode(message)+"&confirm=2")
  16. ElseIf Len(ccnum) < 6 And Len(ccdate) < 4 Then
  17.     ' The order failed
  18.     message = "Please enter a credit card number and expiration date."
  19.     response.write("message="+URLEncode(message)+"&confirm=2")
  20. Else
  21.     ' Generate an order number
  22.     Randomize
  23.     orderno = Int(500000+Rnd(1)*100000)
  24.     message =  "Thank you for your order. Your account was charged " & total & ". Your order number is " & orderno & ". We will send e-mail confirmation to " & email & " when your order ships."
  25.     response.write("message="+URLEncode(message)+"&confirm=1")
  26. End If
  27.  
  28.  
  29. ' Encode a number from 0..15 to a single hex digit
  30. Function HexChar(ByVal i)
  31.     If i < 10 Then
  32.         HexChar = Chr(i+Asc("0"))
  33.     Else
  34.         HexChar = Chr(i-10+Asc("A"))
  35.     End If
  36. End Function
  37.  
  38. ' Encode the control and punctuation characters in a string to %xx hex values
  39. Function URLEncode(ByVal s)
  40.     Dim result, ch
  41.     Do While Len(s) > 0
  42.         ch = Asc(s)
  43.         s = Right(s, Len(s)-1)
  44.         If (ch >= Asc("a") And ch <= Asc("z")) Or (ch >= Asc("A") And ch <= Asc("Z")) Or (ch >= Asc("0") And ch <= Asc("9")) Then
  45.             result = result & Chr(ch)
  46.         ElseIf ch = Asc(" ") Then
  47.             result = result & "+"
  48.         Else
  49.             'result = result & "*" & ch
  50.             'result = result & "!" & (ch/16) & (ch mod 16)
  51.             result = result & "%" & HexChar(Int(ch/16)) & HexChar(ch Mod 16)
  52.         End If
  53.     Loop
  54.     URLEncode = result
  55. End Function
  56.  
  57.  
  58. %>
  59.